/*
Copyright (C) 2011  Christoph Schnack, Berlin (Germany)

This file is part of Tribuit.

    Tribuit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Tribuit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Tribuit.  If not, see <http://www.gnu.org/licenses/>.
*/
package WordTable;

import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.*;
import GuiTools.*;
import Mainframe.*;
import Settings.*;
import Storage.*;

/**
 * @author Christoph Schnack
 *
 */
public class WordTablePresettings {
		Storage MAINVOC;
		Settings SET;
		Language LANG;
		Mainframe MAINFRAME;
		boolean TESTLANGUAGE2,TESTMETAS=true,SHOWPHONETICS=true,SHOWNOTE=false,SHOWESENTENCE = false,SHOWSYNONYMS=true;
		Vector<Word> wtTestvocabulary;
		TribuitMenu MENU;
		
		public WordTablePresettings(Mainframe fr,Storage stor, Settings set,TribuitMenu menu){
			MAINVOC=stor;
			SET=set;
			LANG=SET.getLanguage();
			MAINFRAME=fr;
			MENU=menu;
			new Presettings(MAINVOC,SET,MAINFRAME);
		}
		
		class Presettings extends TribuitWordChooser{
			public Presettings(Storage st, Settings set, Mainframe mf){
				super(st,set,mf,set.getLanguage().getMenuWordTable(),set.getLanguage().getFirstLanguage());
				buildGUI();
				TESTLANGUAGE2=this.getTestLanguage2();
				preTestFrame.addWindowListener(new WindowAdapter(){
					public void windowClosing(WindowEvent e){
						MENU.setWordtableRunning(false);
					}
				});
			}
			
			public void okAction(String vocName,Vector<Word> words){
				WCSettings wcs = new WCSettings(words,vocNameA, vocNameB);
				wcs.setTestLang2Arg(TESTLANGUAGE2);
				wcs.setTestMetasArg(TESTMETAS);
				wcs.setShowPhoneticsArg(SHOWPHONETICS);
				wcs.setShowNoteArg(SHOWNOTE);
				wcs.setShowESentenceArg(SHOWESENTENCE);
				wcs.setShowSynonymsArg(SHOWSYNONYMS);
				new WordTable(MAINVOC,SET,MENU,MAINFRAME,wcs);
			}
			
			public void cancelAction(){
				MENU.setWordtableRunning(false);
			}
			
			public JPanel optionPanel(){
				final JCheckBox phonCB = new JCheckBox(LANG.getPhonetic(),SHOWPHONETICS);
				phonCB.addActionListener(new ActionListener(){
					public void actionPerformed(ActionEvent e){
						SHOWPHONETICS = phonCB.isSelected();
					}
				});
				final JCheckBox noteCB = new JCheckBox(LANG.getNote(),SHOWNOTE);
				noteCB.addActionListener(new ActionListener(){
					public void actionPerformed(ActionEvent e){
						SHOWNOTE = noteCB.isSelected();
					}
				});
				final JCheckBox metaCB = new JCheckBox(LANG.getMetainformation(),TESTMETAS);
				metaCB.addActionListener(new ActionListener(){
					public void actionPerformed(ActionEvent e){
						TESTMETAS = metaCB.isSelected();
					}
				});
				final JCheckBox synonymsCB = new JCheckBox(LANG.getSynonyms(),SHOWSYNONYMS);
				synonymsCB.addActionListener(new ActionListener(){
					public void actionPerformed(ActionEvent e){
						SHOWSYNONYMS = synonymsCB.isSelected();
					}
				});
				final JCheckBox eSentenceCB = new JCheckBox(LANG.getExampleSentence(),SHOWESENTENCE);
				eSentenceCB.addActionListener(new ActionListener(){
					public void actionPerformed(ActionEvent e){
						SHOWESENTENCE = eSentenceCB.isSelected();
					}
				});
				JPanel cbPanel1 = new JPanel();
				cbPanel1.setLayout(new BoxLayout(cbPanel1,BoxLayout.Y_AXIS));
				cbPanel1.add(metaCB);
				cbPanel1.add(phonCB);
				cbPanel1.add(synonymsCB);
				JPanel cbPanel2 = new JPanel();
				cbPanel2.setLayout(new BoxLayout(cbPanel2,BoxLayout.Y_AXIS));
				cbPanel2.add(noteCB);
				cbPanel2.add(eSentenceCB);
				JPanel cbPanel = new JPanel(new GridBagLayout());
				GridBagConstraints gbc = new GridBagConstraints();
				gbc.anchor = GridBagConstraints.NORTHWEST;
				gbc.fill = GridBagConstraints.BOTH;
				gbc.insets = new Insets(5,5,5,5);
				cbPanel.add(cbPanel1,gbc);
				gbc.gridx = 1;
				cbPanel.add(cbPanel2,gbc);
				
				JPanel preToTestPanel = new JPanel();
				preToTestPanel.setLayout(new GridBagLayout());
				GridBagConstraints pttpGBC = new GridBagConstraints();
				pttpGBC.insets = new Insets(5,5,5,5);
				pttpGBC.anchor = GridBagConstraints.NORTHWEST;
				pttpGBC.gridy=1;
				preToTestPanel.add(new LabelPanel(LANG.getShow()+":",cbPanel),pttpGBC);
				return preToTestPanel;
			}
		}
}

